package com.kelvem.saas.workbanch.core.experiment;

public class SpringStartupTimeline {

    /** springboot */
    private static long start;
    private static long end;
    private static long springbootCost;

    public static void setStart() {
        start = System.currentTimeMillis();
    }

    public static void setEnd() {
        end = System.currentTimeMillis();
        springbootCost = end - start;
    }

    /** @Fsm */
    private static long bufFsmStart;
    private static long bufFsmEnd;
    private static long fsmCost = 0L;

    public static void setFsmStart() {
        bufFsmStart = System.currentTimeMillis();
    }

    public static void setFsmEnd() {
        bufFsmEnd = System.currentTimeMillis();
        fsmCost += bufFsmEnd - bufFsmStart;
    }

    /** Mapper */
    private static long bufMapperStart;
    private static long bufMapperEnd;
    private static long mapperCost = 0L;

    public static void setMapperStart() {
        bufMapperStart = System.currentTimeMillis();
    }

    public static void setMapperEnd() {
        bufMapperEnd = System.currentTimeMillis();
        mapperCost += bufMapperEnd - bufMapperStart;
    }

    /** postProcessAfterInitialization */
    private static long bufpostProcessAfterInitializationStart;
    private static long bufpostProcessAfterInitializationEnd;
    private static long postProcessAfterInitializationCost = 0L;

    public static void setPostProcessAfterInitializationStart() {
        bufpostProcessAfterInitializationStart = System.currentTimeMillis();
    }

    public static void setPostProcessAfterInitializationEnd() {
        bufpostProcessAfterInitializationEnd = System.currentTimeMillis();
        postProcessAfterInitializationCost += bufpostProcessAfterInitializationEnd - bufpostProcessAfterInitializationStart;
    }

    /** initializingBean */
    private static long initializingBean;

    public static void setInitializingBean() {
        initializingBean = System.currentTimeMillis();
    }



    public static void print() {
        System.out.println("*********************************************");
        System.out.println(" *       Spring Startup Timeline");
        System.out.println("*********************************************");
        System.out.printf(" *  @Fsm cost                           : %06.3f \n", fsmCost / 1000.0);
        System.out.printf(" *  Mapper cost                         : %06.3f \n", mapperCost / 1000.0);
        System.out.printf(" *  postProcessAfterInitialization cost : %06.3f \n", postProcessAfterInitializationCost / 1000.0);
        System.out.printf(" *  initializingBean time               : %06.3f \n", (initializingBean - start) / 1000.0);
        System.out.printf(" *  Springboot time                     : %06.3f \n", springbootCost / 1000.0);
        System.out.println("*********************************************");
    }


}
